<template>
  <!-- 
    总体思路：
    1. 根据返回的后端数据渲染表格，同时把数据传递到vux
    2. 插槽的回显，从vuex里面获取数据显示
    3. 插槽数据改变的时候，改变vuex里面存储的数据
    4. 提交的时候获取vuex里面的数据进行提交
  -->
  <!-- 
    插槽数据：
    进度完成 // 只渲染不提交
    工程量
    现场照片
    备注
  -->
  <!-- 
    数据设置：
    增加大标题：刚刚获取数据的时候设置，获取的数据获取给原始数据和编辑数据，展示数据根据编辑数据设置
    每行数据设置show属性：打开添加弹窗选择的时候设置
  -->
  <!--  
    当前编辑改变的是插槽里面的编辑数据
  -->
  <div>
    <div style="margin: 12px">
      <a-select
        style="width: 200px"
        v-model:value="yearValue"
        @change="onYearChange"
      >
        <a-select-option v-for="item in selectOpts" :key="item" :value="item">{{
          item
        }}</a-select-option>
      </a-select>
      <a-button
        type="primary"
        @click="onEdit"
        style="margin: 0 10px 0 10px"
        v-if="!isEdit"
        >编辑</a-button
      >
      <a-button
        type="primary"
        @click="addRows"
        v-if="!isEdit"
        style="margin-right: 10px"
        >添加工程项</a-button
      >

      <a-button type="primary" @click="onExport" v-if="!isEdit">导出</a-button>
      <a-button
        type="primary"
        @click="onSubmit"
        v-if="isEdit"
        style="margin: 0 10px 0 10px"
        >提交</a-button
      >
      <a-button @click="onCancel" v-if="isEdit">取消编辑</a-button>
    </div>

    <!-- 表格 -->
    <a-table
      bordered
      :dataSource="dataSource"
      :columns="columns"
      :pagination="false"
      style="margin-bottom: 90px"
    >
    </a-table>

    <!-- 底部填报情况 -->
    <div class="footer">
      <div>指标填报情况：</div>
      <div>
        {{ yearValue }}年，计划实施内容{{ firstVal }}项，计划完成投资{{
          secondVal
        }}万元。截至目前，计划内容已完成{{ thirdVal }}项，实施中{{
          fourthVal
        }}项，完成投资{{ fifthVal }}万元，占当前计划投资{{
          sixthVal
        }}，累计完成{{ seventhVal }}万元，占总投资的{{ eighthVal }}。
      </div>
    </div>
    <addRowsDia
      :visible-of-add="visibleOfAdd"
      @closeOfAdd="closeOfAdd"
      :yearValue="yearValue"
    ></addRowsDia>
  </div>
</template>

<script setup>
import { ref, createVNode } from "vue";
import ProgressCompleted from "./components/ProgressCompleted.vue";
import ScenePhoto from "./components/ScenePhoto.vue";
import Quantities from "./components/Quantities.vue";
import Remark from "./components/Remark.vue";
import { useStore } from "vuex";
import addRowsDia from "./components/addRowsDia.vue";
import { nextTick } from "process";
import { message } from "ant-design-vue";
import {
  getProgressReportDataAPI,
  getYear,
  progressReportUpdate,
} from "@/api/module/constructAndImplement";
import global from "../../global/global.vue";

// 项目id
const projectId = global.xmid;

const store = useStore();
const visibleOfAdd = ref(false);
const yearValue = ref("2023");
const firstVal = ref("");
const secondVal = ref("");
const thirdVal = ref("");
const fourthVal = ref("");
const fifthVal = ref("");
const sixthVal = ref("");
const seventhVal = ref("");
const eighthVal = ref("");

const onYearChange = () => {
  getList();
};

// 获取年份选项
const selectOpts = ref([]);
const getYearData = async () => {
  const res = await getYear();
  selectOpts.value = res.data;
};
getYearData();

// 获取数据
const monthArr = [
  "01",
  "02",
  "03",
  "04",
  "05",
  "06",
  "07",
  "08",
  "09",
  "10",
  "11",
  "12",
];
const getList = async () => {
  // 第一步处理数据，还原成正常样式
  const res = await getProgressReportDataAPI({
    id: projectId,
    year: yearValue.value,
  });
  firstVal.value = res.data.data.targetFillList[0].zbcount;
  secondVal.value = res.data.data.targetFillList[0].ztze;
  thirdVal.value = res.data.data.targetFillList[0].ywc;
  fourthVal.value =
    Number(res.data.data.targetFillList[0].zbcount) -
    Number(res.data.data.targetFillList[0].ywc) -
    Number(res.data.data.targetFillList[0].wwc);
  fifthVal.value = res.data.data.targetFillList[0].jnwctze;
  sixthVal.value = res.data.data.targetFillList[0].ljtzzb;
  seventhVal.value = res.data.data.targetFillList[0].ljtze;
  eighthVal.value = res.data.data.targetFillList[0].ljtzzb;
  // 处理表格数据
  const filterArr = res.data.data.scheduleFillList.filter((item) => {
    return item.scheduleFillDataVoList.length !== 0;
  });
  filterArr.forEach((item) => {
    item.scheduleFillDataVoList.forEach((it) => {
      it.bdmc = item.bdmc;
    });
  });
  let finalArr = [];
  filterArr.forEach((item) => {
    finalArr = finalArr.concat(item.scheduleFillDataVoList);
  });

  // 第二步根据id添加key，处理月份数据
  finalArr.forEach((item) => {
    const itemMonthArr = [];
    item.everyMonthData.forEach((it) => {
      itemMonthArr.push(it.month);
    });
    console.log(itemMonthArr);
    monthArr.forEach((ev) => {
      console.log(itemMonthArr.includes(ev));
      if (!itemMonthArr.includes(ev)) {
        item.everyMonthData.push({ month: ev, gcl: "0" });
      }
    });
  });
  finalArr.forEach((item) => {
    item.everyMonthData = item.everyMonthData.map((it) => {
      return { [it.month]: it.gcl };
    });
    item.key = item.tbId;
  });
  finalArr.forEach((item) => {
    const resultObject = item.everyMonthData.reduce((result, item) => {
      const key = Object.keys(item)[0]; // 获取对象的键
      const value = item[key]; // 获取对象的值
      result[key] = value; // 将键值对添加到结果对象
      return result;
    }, {});
    item.everyMonthData = resultObject;
  });

  store.commit("progressFilling/initNoTitleData", finalArr);
  // 当到目前为止，数据没有大标题，其他一切正常

  // 设置大标段，表格数据绑定数据，isGetData取反
  setShowArray();
};
getList();

// 计算同行数
const calculateSameRow = (gcmc, bdmc) => {
  const compareArr = dataSource.value.filter((item) => item.bdmc === bdmc);
  let count = 0;
  compareArr.forEach((item) => {
    if (item.gcmc === gcmc) {
      count++;
    }
  });
  return count;
};

// /* 表格规则 */
const columns = ref([
  // ⭐ 工程 同时用作整行标题的开始
  {
    title: "工程",
    dataIndex: "gcmc",
    align: "center",
    /* 这是一个循环，一列循环了每整行 */
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // // 判断数据总条数是不是大于两条
      // if (dataSource.value.length >= 2)
      // 整行数据只有bigSection
      if (record.bigSection) {
        obj.attrs.colSpan = 21;
        obj.children = record.bigSection;
        return obj;
        // 整行数据不是仅有bigSection
      } else {
        // 第一个不和前一个比较 最后一个不和后一个比较
        if (index - 1 >= 0 && index + 1 <= dataSource.value.length - 1) {
          if (
            dataSource.value[index - 1].gcmc === dataSource.value[index].gcmc
          ) {
            if (
              dataSource.value[index].gcmc === dataSource.value[index + 1].gcmc
            ) {
              obj.attrs.rowSpan = 0;
            } else {
              obj.attrs.rowSpan = 0;
            }
          } else {
            if (
              dataSource.value[index].gcmc === dataSource.value[index + 1].gcmc
            ) {
              const gcmc = dataSource.value[index].gcmc;
              const bdmc = dataSource.value[index].bdmc;
              obj.attrs.rowSpan = calculateSameRow(gcmc, bdmc);
            } else {
              obj.attrs.rowSpan = 1;
            }
          }
        }
        // 第一行
        if (index === 0) {
          if (
            dataSource.value[index].gcmc === dataSource.value[index + 1].gcmc
          ) {
            const gcmc = dataSource.value[index].gcmc;
            const bdmc = dataSource.value[index].bdmc;
            obj.attrs.rowSpan = calculateSameRow(gcmc, bdmc);
          } else {
            obj.attrs.rowSpan = 1;
          }
        }
        // 最后一行
        if (index === dataSource.value.length - 1) {
          if (
            dataSource.value[index - 1].gcmc === dataSource.value[index].gcmc
          ) {
            obj.attrs.rowSpan = 0;
          } else {
            obj.attrs.rowSpan = 1;
          }
        }
      }
      return obj;
    },
  },
  //⭐ 项目
  {
    title: "项目",
    dataIndex: "xmmc",
    align: "center",
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
      }
      return obj;
    },
  },
  // ⭐内容
  {
    title: "内容",
    dataIndex: "content",
    align: "center",
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
      }
      return obj;
    },
  },
  // ⭐进度完成 插槽
  {
    title: "进度完成",
    dataIndex: "progressCompleted", // 不需要
    align: "center",
    width: 300,
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
        return obj;
      } else {
        return createVNode(ProgressCompleted, {
          index: index,
          isGetData: isGetData.value,
        });
      }
    },
  },
  // 累计完成
  {
    title: "累计完成",
    children: [
      // ⭐工程量 插槽
      {
        title: "工程量",
        dataIndex: "workAmount", // 不需要
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: text,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
            return obj;
          } else {
            return createVNode(Quantities, {
              isEdit: isEdit.value,
              index: index,
              isGetData: isGetData.value,
            });
          }
        },
      },
      // ⭐投资（万元）
      {
        title: "投资（万元）",
        dataIndex: "tze",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: text,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          }

          return obj;
        },
      },
    ],
  },
  // ⭐状态分析  半插槽
  {
    title: "状态分析",
    dataIndex: "ztfx",
    align: "center",
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
      } else {
        if (text > 95) {
          obj.children = "进度正常";
        }
        if (text <= 95) {
          obj.children = "进度慢" + record.qd;
        }
      }
      return obj;
    },
  },
  // ⭐现场照片 插槽
  {
    title: "现场照片",
    dataIndex: "photoDataVo",
    align: "center",
    customRender: ({ text, record, index }) => {
      const obj = {
        children: 0,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
        return obj;
      } else {
        return createVNode(ScenePhoto, {
          isEdit: isEdit.value,
          isGetData: isGetData.value,
          index: index,
        });
      }
    },
  },
  // ⭐今年每月工程量
  {
    title: "今年每月工程量",
    children: [
      // 一月
      {
        title: "1月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["01"];
            // 根据工程量计算
            if (Object.values(text).every((item) => item === "0")) {
              obj.children = record.gcl;
            }
            // // 标记截止日期
            // if (record.deadline === "1") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }
          return obj;
        },
      },
      // 二月
      {
        title: "2月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["02"];
            // 判断当月有没有给数据
            if (!Number(record.february) && Number(record.january)) {
              obj.children = Number(record.gcl) - Number(text["01"]);
            }
            // // 标记截止日期
            // if (record.deadline === "2") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }
          return obj;
        },
      },
      // 三月
      {
        title: "3月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["03"];
            // 判断当月有没有给数据
            if (!Number(record.march) && Number(record.february)) {
              obj.children =
                Number(record.gcl) - (Number(text["01"]) + Number(text["02"]));
            }
            // if (record.deadline === "3") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 四月
      {
        title: "4月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["04"];
            // 判断当月有没有给数据
            if (!Number(record.april) && Number(record.march)) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) + Number(text["02"]) + Number(text["03"]));
            }
            // if (record.deadline === "4") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 五月
      {
        title: "5月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["05"];
            // 判断当月有没有给数据
            if (!Number(record.may) && Number(record.april)) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]));
            }
            // if (record.deadline === "5") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 六月
      {
        title: "6月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["06"];
            // 判断当月有没有给数据
            if (!Number(record.june) && Number(record.may)) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]));
            }
            // if (record.deadline === "6") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 七月
      {
        title: "7月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["07"];
            // 判断当月有没有给数据
            if (!Number(record.july) && Number(record.june)) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]));
            }
            // if (record.deadline === "7") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 八月
      {
        title: "8月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["08"];
            // 判断当月有没有给数据
            if (!Number(record.august) && Number(record.july)) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]) +
                  Number(text["07"]));
            }
            // if (record.deadline === "8") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 九月
      {
        title: "9月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["09"];
            // 判断当月有没有给数据
            if (!Number(record.september) && Number(record.august)) {
              obj.children =
                Number(record.workAmount.number) -
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]) +
                  Number(text["07"]) +
                  Number(text["08"]));
            }
            // if (record.deadline === "9") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
        slots: { title: "september" },
      },
      // 十月
      {
        title: "10月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["10"];
            // 判断当月有没有给数据
            if (!Number(text["10"]) && Number(text["09"])) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]) +
                  Number(text["07"]) +
                  Number(text["08"]) +
                  Number(text["09"]));
            }
            // if (record.deadline === "10") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 十一月
      {
        title: "11月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: text,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["11"];
            // 判断当月有没有给数据
            if (!Number(text["11"]) && Number(text["10"])) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]) +
                  Number(text["07"]) +
                  Number(text["08"]) +
                  Number(text["09"]) +
                  Number(text["10"]));
            }
            // if (record.deadline === "11") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
      // 十二月
      {
        title: "12月",
        dataIndex: "everyMonthData",
        align: "center",
        customRender: ({ text, record, index }) => {
          const obj = {
            children: 0,
            attrs: {},
          };
          // 判断条件
          if (record.bigSection) {
            obj.attrs.colSpan = 0;
          } else {
            obj.children = text["12"];
            // 判断当月有没有给数据
            if (!Number(text["12"]) && Number(text["11"])) {
              obj.children =
                Number(record.gcl) -
                (Number(text["01"]) +
                  Number(text["02"]) +
                  Number(text["03"]) +
                  Number(text["04"]) +
                  Number(text["05"]) +
                  Number(text["06"]) +
                  Number(text["07"]) +
                  Number(text["08"]) +
                  Number(text["09"]) +
                  Number(text["10"]) +
                  Number(text["11"]));
            }
            // if (record.deadline === "12") {
            //   obj.children = obj.children + "（截止日期）";
            // }
          }

          return obj;
        },
      },
    ],
  },
  // ⭐备注
  {
    title: "备注",
    dataIndex: "remark",
    align: "center",
    customRender: ({ text, record, index }) => {
      const obj = {
        children: text,
        attrs: {},
      };
      // 判断条件
      if (record.bigSection) {
        obj.attrs.colSpan = 0;
        return obj;
      } else {
        return createVNode(Remark, {
          isEdit: isEdit.value,
          isGetData: isGetData.value,
          index: index,
        });
      }
    },
  },
]);
/* 表格数据 */
const dataSource = ref([]);

// // 试验数据
// const testData = ref([
//   {
//     id: 11,
//     section: "测试标段1",
//     engineering: "建筑工程",
//     project: "土石坝工程",
//     content: "土料填筑",
//     progressCompleted: {
//       month: "10",
//       date: "20",
//       total: "1000",
//       year: "500",
//     },
//     workAmount: {
//       number: "211",
//       unit: "km",
//     },
//     investment: "1000万元",
//     stateAnalysis: "进度正常",
//     photoOfTheScene: [
//       {
//         time: "2023",
//         photos: [
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//         ],
//       },
//     ],
//     remark: "备注",
//     january: "10",
//     february: "10",
//     march: "10",
//     april: "10",
//     may: "10",
//     june: "10",
//     july: "10",
//     august: "10",
//     september: "20",
//     october: "0",
//     november: "0",
//     december: "0",
//     halfYear: "60",
//     deadline: "9",
//   },
//   {
//     id: 22,
//     section: "测试标段1",
//     engineering: "建筑工程",
//     project: "土石坝工程",
//     content: "土料填筑",
//     progressCompleted: {
//       month: "10",
//       date: "20",
//       total: "1000",
//       year: "500",
//     },
//     workAmount: {
//       number: "112",
//       unit: "km",
//     },
//     investment: "1000万元",
//     stateAnalysis: "进度正常",
//     photoOfTheScene: [
//       {
//         time: "2023",
//         photos: [
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//         ],
//       },
//     ],
//     remark: "备注",
//     january: "10",
//     february: "10",
//     march: "10",
//     april: "10",
//     may: "10",
//     june: "10",
//     july: "10",
//     august: "10",
//     september: "20",
//     october: "0",
//     november: "0",
//     december: "0",
//     halfYear: "60",
//     deadline: "10",
//   },
//   {
//     id: 33,
//     section: "测试标段1",
//     engineering: "建筑工程",
//     project: "工程",
//     content: "土料填筑",
//     progressCompleted: {
//       month: "10",
//       date: "20",
//       total: "1000",
//       year: "500",
//     },
//     workAmount: {
//       number: "31",
//       unit: "km",
//     },
//     investment: "1000万元",
//     stateAnalysis: "进度正常",
//     photoOfTheScene: [
//       {
//         time: "2023",
//         photos: [
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//         ],
//       },
//     ],
//     remark: "备注",
//     january: "10",
//     february: "10",
//     march: "10",
//     april: "10",
//     may: "10",
//     june: "10",
//     july: "10",
//     august: "10",
//     september: "20",
//     october: "0",
//     november: "0",
//     december: "0",
//     halfYear: "0",
//     deadline: "9",
//   },
//   {
//     id: 44,
//     section: "测试标段1",
//     engineering: "建筑工程",
//     project: "工程",
//     content: "土料填筑",
//     progressCompleted: {
//       month: "10",
//       date: "20",
//       total: "1000",
//       year: "500",
//     },
//     workAmount: {
//       number: "4",
//       unit: "km",
//     },
//     investment: "1000万元",
//     stateAnalysis: "进度正常",
//     photoOfTheScene: [
//       {
//         time: "2023",
//         photos: [
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//         ],
//       },
//     ],
//     remark: "备注",
//     january: "10",
//     february: "10",
//     march: "10",
//     april: "10",
//     may: "10",
//     june: "10",
//     july: "10",
//     august: "10",
//     september: "20",
//     october: "0",
//     november: "0",
//     december: "0",
//     halfYear: "0",
//     deadline: "10",
//   },
//   {
//     id: 55,
//     section: "测试标段2",
//     engineering: "建筑工程",
//     project: "工程",
//     content: "土料填筑",
//     progressCompleted: {
//       month: "10",
//       date: "20",
//       total: "1000",
//       year: "500",
//     },
//     workAmount: {
//       number: "4",
//       unit: "km",
//     },
//     investment: "1000万元",
//     stateAnalysis: "进度正常",
//     photoOfTheScene: [
//       {
//         time: "2023",
//         photos: [
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//           "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
//         ],
//       },
//     ],
//     remark: "备注",
//     january: "10",
//     february: "10",
//     march: "10",
//     april: "10",
//     may: "10",
//     june: "10",
//     july: "10",
//     august: "10",
//     september: "20",
//     october: "0",
//     november: "0",
//     december: "0",
//     halfYear: "0",
//     deadline: "10",
//   },
// ]);

// 公共逻辑设置展示数据，
const setShowArray = () => {
  // 第三步设置大标段
  const arrayWithBig = [];
  let previousSection = "";
  store.state.progressFilling.noTitleData.forEach((item) => {
    if (item.bdmc !== previousSection) {
      arrayWithBig.push({ bigSection: item.bdmc });
    }
    arrayWithBig.push(item);
    previousSection = item.bdmc;
  });
  // 赋值原始数据
  store.commit("progressFilling/initProgressFillingData", arrayWithBig);
  // 赋值编辑数据(暂未使用)
  store.commit("progressFilling/initEditProgressFillingData", arrayWithBig);
  // 使用编辑数据
  dataSource.value = store.state.progressFilling.editProgressFillingData;
  nextTick(() => {
    isGetData.value = !isGetData.value;
  });
  setTimeout(() => {
    console.log(dataSource.value);
  }, 2000);
};
// 是否获取数据
const isGetData = ref(false);

// 是否处于编辑状态
const isEdit = ref(false);
// 点击编辑
const onEdit = () => {
  // 初始化编辑数据
  store.commit("progressFilling/initParamsData", []);
  isEdit.value = true;
};

// 点击提交
const onSubmit = async () => {
  // 获取store里面的数据进行提交
  const paramsData = store.state.progressFilling.paramsData;
  console.log(paramsData);
  if (paramsData.length === 0) {
    return false;
  }
  console.log(paramsData);
  const res = await progressReportUpdate(paramsData);
  console.log(res);
  getList(); // 重新获取数据
  message.success("提交成功");
  isEdit.value = false;
};

// 点击取消
const onCancel = () => {
  // 将编辑数据变回原始数据
  store.commit(
    "progressFilling/initEditProgressFillingData",
    store.state.progressFilling.progressFillingData
  );
  setShowArray();
  isEdit.value = false;
};

// 点击添加
const addRows = () => {
  visibleOfAdd.value = true;
};

// 关闭添加窗
const closeOfAdd = () => {
  console.log(123);
  // 重新获取数据
  getList();
  visibleOfAdd.value = false;
};

// 点击导出
const onExport = () => {
  console.log("点击导出");
};
</script>

<style lang="less" scoped>
.footer {
  width: 100%;
  padding: 10px;
  background-color: #fff;
  position: fixed;
  bottom: 0;
}
</style>
